import time
import requests
import json
import math
from openpyxl import load_workbook


etime = int(time.time())   # 结束时间
# metric_dict = {"内存使用率":"mem.bytes.used.percent", "存储使用率":"disk.bytes.used.percent", "系统负载":"cpu.loadavg.15",
#                "网络入带宽":"net.in.bits.total", "网络出带宽":"net.out.bits.total", "建连数":"net.sockets.tcp.inuse", "半打开数":"net.sockets.tcp.timewait"
# }
headers = {"X-User-Token":"756283292c03bd29dbf8a721f5ca26bc", "content-type":"application/json"}


def avg(list_s):
    ret = 0
    times = 0
    for i in list_s:
        ret += i
        times += 1
    ret = ret/times
    return ret

def variance(list_s):
    ret = 0
    times = 0
    avg_n = avg(list_s)
    for i in list_s:
        ret += (i - avg_n)**2
        times += 1
    ret = ret/times
    return math.sqrt(ret)

def inspection(ip_col, path_excel, cycle, sheet="Sheet1"):
    # 从excel中读取endpoint、metric
    wb = load_workbook(path_excel)
    ws = wb[sheet]


    # stime = int(etime - cycle*24*3600)
    # data = {'endpoints':endpoints, 'metric':"metric", 'start':stime, 'end': etime, 'tags':"tags"}
    # data = json.dumps(data)
    # ret = requests.post("https://nightingale.smyoa.com/api/transfer/data/ui", headers=headers, data=data)
    # infos = json.loads(ret.text)['dat']
    # return infos


# d:/py文件/py脚本/test.xlsx
inspection('C', 'd:/py文件/py脚本/test.xlsx', 1, sheet="Sheet3")